package tests.cases {
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import org.flexunit.Assert;
	
	import vo.EventVO;
	
	public class TestCalendar extends DefaultTestCase {
		
		private var calendarService:RemoteObject;
		
		[Before]
		public function setUp():void {
			
			calendarService = new RemoteObject();
			calendarService.destination = "amfphp";
			calendarService.source = "CalendarService";
		}
		
		[After]
		public function tearDown():void {
			
			calendarService = null;
		}
		
		// ----------------------------------------------------------------
		// TEST ADD EVENT
		// ----------------------------------------------------------------
		private static var savedEventUID:String;
		
		[Test(async,order=1)]
		public function testAddEvent():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				groupUID: "group001",
				eventDate: "2009-11-28",
				eventName: "Test Event",
				description: "This is a test event"
			};
			
			var token:AsyncToken = calendarService.addEvent(argsVO.sessionID, argsVO.groupUID, argsVO.eventDate, argsVO.eventName, argsVO.description);
			runAsyncTest(token, argsVO, handleAddEvent);
		}
		
		private function handleAddEvent(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			savedEventUID = message.result as String;
		}
		
		// ----------------------------------------------------------------
		// TEST EDIT EVENT
		// ----------------------------------------------------------------
		[Test(async,order=2)]
		public function testEditEvent():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				eventUID: savedEventUID,
				eventDate: "2009-11-25",
				eventName: "Test Event",
				description: "This is a test event, now moved to the 25th"
			};
			
			var token:AsyncToken = calendarService.editEvent(argsVO.sessionID, argsVO.eventUID, argsVO.eventDate, argsVO.eventName, argsVO.description);
			runAsyncTest(token, argsVO, handleEditEvent);
		}
		
		private function handleEditEvent(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST GET EVENT LIST
		// ----------------------------------------------------------------
		[Test(async,order=3)]
		public function testGetEventList():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				groupUID: "group001",
				userUID: "user001"
			};
			
			var token:AsyncToken = calendarService.getEventList(argsVO.sessionID, argsVO.groupUID, argsVO.userUID);
			runAsyncTest(token, argsVO, handleGetEventList);
		}
		
		private function handleGetEventList(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			Assert.assertTrue((message.result.length > 0));
		}
		
		// ----------------------------------------------------------------
		// TEST GET EVENT DETAILS
		// ----------------------------------------------------------------
		[Test(async,order=4)]
		public function testGetEventDetails():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				eventUID: savedEventUID,
				userUID: "user001"
			};
			
			var token:AsyncToken = calendarService.getEventDetails(argsVO.sessionID, argsVO.eventUID, argsVO.userUID);
			runAsyncTest(token, argsVO, handleGetEventDetails);
		}
		
		private function handleGetEventDetails(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			Assert.assertTrue((message.result is EventVO));
		}
		
		// ----------------------------------------------------------------
		// TEST RSVP EVENT
		// ----------------------------------------------------------------
		[Test(async,order=5)]
		public function testRsvpEvent():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				eventUID: savedEventUID,
				userUID: "user001",
				unrsvp: false
			};
			
			var token:AsyncToken = calendarService.rsvpEvent(argsVO.sessionID, argsVO.eventUID, argsVO.userUID, argsVO.unrsvp);
			runAsyncTest(token, argsVO, handleRsvpEvent);
		}
		
		private function handleRsvpEvent(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNull(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST UN-RSVP EVENT
		// ----------------------------------------------------------------
		[Test(async,order=6)]
		public function testUnRsvpEvent():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				eventUID: savedEventUID,
				userUID: "user001",
				unrsvp: true
			};
			
			var token:AsyncToken = calendarService.rsvpEvent(argsVO.sessionID, argsVO.eventUID, argsVO.userUID, argsVO.unrsvp);
			runAsyncTest(token, argsVO, handleUnRsvpEvent);
		}
		
		private function handleUnRsvpEvent(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNull(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST DELETE EVENT
		// ----------------------------------------------------------------
		[Test(async,order=7)]
		public function testDeleteEvent():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				eventUID: savedEventUID
			};
			
			var token:AsyncToken = calendarService.deleteEvent(argsVO.sessionID, argsVO.eventUID);
			runAsyncTest(token, argsVO, handleDeleteEvent);
		}
		
		private function handleDeleteEvent(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
		}
	}
}